﻿using Abp.Web.Models;
using Abp.Web.Mvc.Controllers;
using Abp.Web.Mvc.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyABP.Web.Controllers
{
    public class ErrorController : AbpController
    {
        private readonly IErrorInfoBuilder _errorInfoBuilder;

        public ErrorController(IErrorInfoBuilder errorInfoBuilder)
        {
            _errorInfoBuilder = errorInfoBuilder;
        }

        public ActionResult Index()
        {
            //var exHandlerFeature = HttpContext.Features.Get<IExceptionHandlerFeature>();

            //var exception = exHandlerFeature != null
            //                    ? exHandlerFeature.Error
            //                    : new Exception("Unhandled exception!");
            //var exception =  new Exception("Unhandled exception!");
            var exHandlerFeature = HttpContext.Error.InnerException;
            
            var exception = exHandlerFeature != null
                                ? exHandlerFeature
                                : new Exception("Unhandled exception!");
            return View(
                "Error",
                new ErrorViewModel(
                    _errorInfoBuilder.BuildForException(exception),
                    exception
                )
            );
        }
    }
}